<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:p="pilferpage"
	xmlns:xlink="http://www.w3.org/1999/xlink"
	xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0"
	xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
	xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0"
	xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"
	xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"
	xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0"
	xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0"
	xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"
	xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0"
	xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0"
	xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0"
	xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0"
	>


	<xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>

	<xsl:template match="/p:page">
		<office:document-content office:version="1.1">
			<office:automatic-styles>
				<style:style style:name="bold" style:family="text">
					<style:text-properties fo:font-weight="bold" style:font-weight-asian="bold" style:font-weight-complex="bold"/>
				</style:style>
				<style:style style:name="emphasis" style:family="text">
					<style:text-properties fo:font-style="italic" style:font-style-asian="italic" style:font-style-complex="italic"/>
				</style:style>
				<style:style style:name="strong" style:family="text">
					<style:text-properties fo:font-weight="bold" style:font-weight-asian="bold" style:font-weight-complex="bold"/>
				</style:style>
				<style:style style:name="italics" style:family="text">
					<style:text-properties fo:font-style="italic" style:font-style-asian="italic" style:font-style-complex="italic"/>
				</style:style>
				<text:list-style style:name="orderedList">
					<text:list-level-style-number text:level="1" style:num-format=""/>
					<text:list-level-style-number text:level="2" style:num-format=""/>
					<text:list-level-style-number text:level="3" style:num-format=""/>
					<text:list-level-style-number text:level="4" style:num-format=""/>
					<text:list-level-style-number text:level="5" style:num-format=""/>
					<text:list-level-style-number text:level="6" style:num-format=""/>
					<text:list-level-style-number text:level="7" style:num-format=""/>
					<text:list-level-style-number text:level="8" style:num-format=""/>
					<text:list-level-style-number text:level="9" style:num-format=""/>
					<text:list-level-style-number text:level="10" style:num-format=""/>
				</text:list-style>
				<text:list-style style:name="bulletedList">
					<text:list-level-style-bullet text:level="1" text:style-name="Bullet_20_Symbols" style:num-suffix="." text:bullet-char="●">
						<style:list-level-properties text:space-before="0.25in" text:min-label-width="0.25in"/>
						<style:text-properties style:font-name="StarSymbol"/>
					</text:list-level-style-bullet>

					<text:list-level-style-bullet text:level="2" text:style-name="Bullet_20_Symbols" style:num-suffix="." text:bullet-char="○">
						<style:list-level-properties text:space-before="0.5in" text:min-label-width="0.25in"/>
						<style:text-properties style:font-name="StarSymbol"/>
					</text:list-level-style-bullet>

					<text:list-level-style-bullet text:level="3" text:style-name="Bullet_20_Symbols" style:num-suffix="." text:bullet-char="■">
						<style:list-level-properties text:space-before="0.75in" text:min-label-width="0.25in"/>
						<style:text-properties style:font-name="StarSymbol"/>
					</text:list-level-style-bullet>

					<text:list-level-style-bullet text:level="4" text:style-name="Bullet_20_Symbols" style:num-suffix="." text:bullet-char="●">
						<style:list-level-properties text:space-before="1in" text:min-label-width="0.25in"/>
						<style:text-properties style:font-name="StarSymbol"/>
					</text:list-level-style-bullet>

					<text:list-level-style-bullet text:level="5" text:style-name="Bullet_20_Symbols" style:num-suffix="." text:bullet-char="○">
						<style:list-level-properties text:space-before="1.25in" text:min-label-width="0.25in"/>
						<style:text-properties style:font-name="StarSymbol"/>
					</text:list-level-style-bullet>

					<text:list-level-style-bullet text:level="6" text:style-name="Bullet_20_Symbols" style:num-suffix="." text:bullet-char="■">
						<style:list-level-properties text:space-before="1.5in" text:min-label-width="0.25in"/>
						<style:text-properties style:font-name="StarSymbol"/>
					</text:list-level-style-bullet>

					<text:list-level-style-bullet text:level="7" text:style-name="Bullet_20_Symbols" style:num-suffix="." text:bullet-char="●">
						<style:list-level-properties text:space-before="1.75in" text:min-label-width="0.25in"/>
						<style:text-properties style:font-name="StarSymbol"/>
					</text:list-level-style-bullet>

					<text:list-level-style-bullet text:level="8" text:style-name="Bullet_20_Symbols" style:num-suffix="." text:bullet-char="○">
						<style:list-level-properties text:space-before="2in" text:min-label-width="0.25in"/>
						<style:text-properties style:font-name="StarSymbol"/>
					</text:list-level-style-bullet>

					<text:list-level-style-bullet text:level="9" text:style-name="Bullet_20_Symbols" style:num-suffix="." text:bullet-char="■">
						<style:list-level-properties text:space-before="2.25in" text:min-label-width="0.25in"/>
						<style:text-properties style:font-name="StarSymbol"/>
					</text:list-level-style-bullet>

					<text:list-level-style-bullet text:level="10" text:style-name="Bullet_20_Symbols" style:num-suffix="." text:bullet-char="●">
						<style:list-level-properties text:space-before="2.5in" text:min-label-width="0.25in"/>
						<style:text-properties style:font-name="StarSymbol"/>
					</text:list-level-style-bullet>
				</text:list-style>

				<style:style style:name="bulletedListParagraph" style:family="paragraph" style:parent-style-name="Standard" style:list-style-name="bulletedList">
					<style:paragraph-properties>
						<style:tab-stops>
							<style:tab-stop style:position="0.5in"/>
						</style:tab-stops>
					</style:paragraph-properties>
					<style:text-properties style:use-window-font-color="true" fo:font-size="12pt" fo:language="en" fo:country="US" style:font-name-asian="Sans Serif" style:font-size-asian="12pt" style:language-asian="en" style:country-asian="US" style:font-name-complex="Tahoma" style:font-size-complex="12pt" style:language-complex="en" style:country-complex="US"/>
				</style:style>

				<style:style style:name="image" style:family="graphic" style:parent-style-name="Graphics">
					<style:graphic-properties style:wrap="dynamic" style:number-wrapped-paragraphs="no-limit" style:wrap-contour="false" style:vertical-pos="from-top" style:vertical-rel="paragraph" style:horizontal-pos="from-left" style:horizontal-rel="paragraph" fo:background-color="#ffffff" style:background-transparency="0%" fo:padding="0.0102in" fo:border="none" style:mirror="none" fo:clip="rect(0in 0in 0in 0in)" draw:luminance="0%" draw:contrast="0%" draw:red="0%" draw:green="0%" draw:blue="0%" draw:gamma="100%" draw:color-inversion="false" draw:image-opacity="100%" draw:color-mode="standard">
						<style:background-image/>
					</style:graphic-properties>
				</style:style>
			</office:automatic-styles>
			<office:body>
				<office:text>
					<xsl:apply-templates/>
				</office:text>
			</office:body>
		</office:document-content>
	</xsl:template>


	<xsl:template match="p:title">
		<text:h text:outline-level="{count(ancestor::p:section)+1}">
			<xsl:apply-templates/>
		</text:h>
	</xsl:template>

	<xsl:template match="p:paragraph">
		<xsl:element name="text:p">
			<xsl:apply-templates/>
		</xsl:element>
	</xsl:template>

	<xsl:template match="p:table">
		<xsl:variable name="tableId">
			<xsl:text>Table</xsl:text>
			<xsl:number/>
		</xsl:variable>
		<table:table table:style-name="{$tableId}">
			<xsl:attribute name="table:name">
				<xsl:choose>
					<xsl:when test="p:title"><xsl:value-of select="p:title"/></xsl:when>
					<xsl:otherwise><xsl:value-of select="$tableId"/></xsl:otherwise>
				</xsl:choose>
			</xsl:attribute>
			<xsl:choose>
				<xsl:when test="p:head/p:row[1]/p:cell">
					<xsl:for-each select="p:head/p:row[1]/p:cell">
						<table:table-column/>
					</xsl:for-each>
				</xsl:when>
				<xsl:otherwise>
					<xsl:for-each select="p:row[1]/p:cell | p:body/p:row[1]/p:cell">
						<table:table-column/>
					</xsl:for-each>
				</xsl:otherwise>
			</xsl:choose>
			<xsl:apply-templates select="p:head"/>
			<xsl:apply-templates select="p:row | p:body"/>
			<xsl:apply-templates select="p:foot"/>
		</table:table>
	</xsl:template>

	<xsl:template match="p:row">
		<table:table-row>
			<xsl:apply-templates select="p:cell"/>
		</table:table-row>
		<xsl:apply-templates select="p:row"/>
	</xsl:template>

	<xsl:template match="p:cell">
		<xsl:variable name="innerText">
			<xsl:for-each select="text()">
				<xsl:value-of select="."/>
			</xsl:for-each>
		</xsl:variable>
		<table:table-cell office:value-type="string">
			<xsl:choose>
				<xsl:when test="normalize-space($innerText)">
					<xsl:element name="text:p">
						<xsl:apply-templates select="text()"/>
					</xsl:element>
					<xsl:apply-templates select="*"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:apply-templates/>
				</xsl:otherwise>
			</xsl:choose>
		</table:table-cell>
	</xsl:template>

	<xsl:template match="p:link">
		<xsl:element name="text:a">
			<xsl:attribute name="xlink:href"><xsl:value-of select="@url"/></xsl:attribute>
			<xsl:apply-templates/>
		</xsl:element>
	</xsl:template>

</xsl:stylesheet>
